#ifndef __AI_SERVICE_TASK_QUEUE_H__
#define __AI_SERVICE_TASK_QUEUE_H__

#include <queue>
#include <mutex>
#include <functional>
#include <condition_variable>
#include <cstddef>
#include <thread>
#include <cstdio>
#include <string>
#include <map>
#include <memory>

#include "utils.h"
#include "params.h"
#include "task.h"

namespace ai_service {

using TaskExec = std::function<Ret(void)>;

class AsyncTaskQueue
{
public:
    AsyncTaskQueue(const size_t max_size = 0) : m_max_size(max_size) {}
    AsyncTaskQueue(const AsyncTaskQueue&) = delete;
    AsyncTaskQueue& operator=(const AsyncTaskQueue&) = delete;


    Ret Push(std::pair<AsyncTaskBase*, TaskExec> task);
    Ret Pop(std::pair<AsyncTaskBase*, TaskExec>& task);
    Ret Loop(bool& flag);

private:
    Ret Notify();
    Ret Wait();

    std::mutex m_mutex;
    std::condition_variable m_cond;
    size_t m_max_size;
    std::queue<std::pair<AsyncTaskBase*, TaskExec>> m_queue;
    std::string m_name = "AsyncTaskQueue";
}; // AsyncTaskQueue



}

#endif // __AI_SERVICE_TASK_H__